package com.kunsan.compose

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.kunsan.compose.compoents.login.PrivacyAndAgreement
import com.kunsan.compose.ui.theme.Color3D3D3D
import com.kunsan.compose.ui.theme.Color666666
import com.kunsan.compose.ui.theme.LineColor
import com.kunsan.compose.ui.theme.MyApplicationTheme
import com.kunsan.compose.ui.theme.primaryColor

@Composable
fun OneClickLogin(navController: NavHostController) {


    val localPhoneNum by remember { mutableStateOf("1445") }
    val serviceProvider by remember { mutableStateOf("XXXX") }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(horizontal = 37.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Spacer(modifier = Modifier.height(123.dp))

        Image(
            painter = painterResource(id = R.drawable.icon_login_app_logo),
            contentDescription = "Account Icon"
        )
        Spacer(modifier = Modifier.height(38.dp))

        Text(fontSize = 24.sp, text = localPhoneNum)

        Spacer(modifier = Modifier.height(10.dp))
        Text(fontSize = 14.sp, color = Color666666, text = "认证服务由$serviceProvider 提供")

        Spacer(modifier = Modifier.height(23.dp))

        FilledTonalButton(
            onClick = {
            },
            colors = ButtonDefaults.buttonColors(containerColor = primaryColor), modifier = Modifier.fillMaxWidth(), shape = RoundedCornerShape(6.dp)
        ) {
            Text("本机号码一键登录", modifier = Modifier.padding(vertical = 6.dp), fontSize = 14.sp)
        }
        Spacer(modifier = Modifier.height(24.dp))

        OutlinedButton (
            onClick = {
                navController.navigate(MeetingDestinations.LOGIN_ROUTE)
            },
            modifier = Modifier
                .fillMaxWidth(),
            border = BorderStroke(1.dp, LineColor),
            shape = RoundedCornerShape(6.dp),

            ) {
            Text("其他手机号码登录", modifier = Modifier.padding(vertical = 6.dp), color = Color3D3D3D, fontSize = 14.sp)
        }

        Spacer(modifier = Modifier.height(30.dp))


        PrivacyAndAgreement()
    }

}

@Preview(showBackground = true)
@Composable
fun OneClickLoginPreview() {
    MyApplicationTheme {
        OneClickLogin(rememberNavController())
    }
}